﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace BDDSynth
{
    public partial class CreateMySQL : Form
    {
        MySqlConnection cnw;
        public CreateMySQL()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String connStrMysql = "server=localhost;user id=root; password=; database=''; pooling=false";
            cnw = new MySqlConnection(connStrMysql);
            try
            {
                cnw.Open();
                string Mysqlrequete = "CREATE DATABASE " + mysqlbasename.Text;
                MySqlCommand command = new MySqlCommand(Mysqlrequete, cnw);
                command.ExecuteNonQuery();
                cnw.Close();

                string connStrMysql2 = "server=localhost;user id=root; password=; database=" + mysqlbasename.Text + "; pooling=false";
                MySqlConnection cnw2;
                cnw2 = new MySqlConnection(connStrMysql2);
                cnw2.Open();
                string Mysqlrequete2 = "CREATE TABLE " + mysqltablename.Text + "(" + mysqlchamp.Text + " " + comboBox1.Text + ", " + mysqlcham2.Text + " " + comboBox2.Text + ", " + mysqlchamp3.Text + " " + comboBox3.Text + ", " + mysqlchamp4.Text + " " + comboBox4.Text + ")";
                MySqlCommand command2 = new MySqlCommand(Mysqlrequete2, cnw2);
                command2.ExecuteNonQuery();
                Close();
            }
            catch
            {
                MessageBox.Show("Erreur Création de la base de données MySql");
            }
        }
    }
}
